package cn.com.guanying.android.logic;

import java.util.ArrayList;
import java.util.HashMap;

import cn.com.guanying.javacore.v11.common.FLog;
import cn.com.guanying.javacore.v11.core.Request;
import cn.com.guanying.javacore.v11.core.RequestParser;
import cn.com.guanying.javacore.v11.core.RequestWrapper;
import cn.com.guanying.javacore.v11.core.Response;
import cn.com.guanying.javacore.v11.datacontainer.DataControler;
import cn.com.guanying.javacore.v11.models.FilmInfo;

public class LoginLogic extends BaseLogic {
	private HashMap<String ,String> mnav = null;//存储导航信息
	public final static int EVENT_REQ_MNAV = 1;//获取导航
	public final static int EVENT_FILM_LIST = 3;//获取导航
	public final static int EVENT_GETMNAV_ERROR =4 ;//请求发送失败
	private DataControler dataControler = DataControler.getInstance();
	public void onRequestFinshed(Response resp) {
		if(resp.getmResponseCode()==Response.CODE_SUCCESS){
			if(resp.getmType() == EVENT_REQ_MNAV){
				mnav = RequestParser.parseMNAV(resp.getmBody()); 
				dataControler.saveProperty(mnav);
				FLog.i(mnav.toString());
				notify(EVENT_REQ_MNAV);
			}else if(resp.getmType() == EVENT_FILM_LIST){
				HashMap<String,ArrayList<FilmInfo>> data = RequestParser.getFilmList(resp.getmBody());
				FLog.i(data.toString());
			}
		}else{
			notify(EVENT_GETMNAV_ERROR);
		}
	}
	
	/**
	 * 发送获取导航的请求
	 */
	public void getMNAV(){
		Request request = new Request(this);
		String xml = RequestWrapper.getMNAV();
		request.setmBody(xml);
		request.setmType(EVENT_REQ_MNAV);
		request.setmUrl("http://58.68.247.177:12345/mobile/login");
		sendRequest(request);
	}
	/**
	 * 发送获取导航的请求
	 */
	public void getFilmList(){
		Request request = new Request(this);
		String xml = RequestWrapper.getFilmList();
		request.setmBody(xml);
		request.setmType(EVENT_FILM_LIST);
		request.setmUrl("http://58.68.247.177:12345/mobile/playing");
		sendRequest(request);
	}
	protected void init() {
		
	}
	protected void destroy() {

	}

}
